package com.suxin.socket.yinfei;

import com.suxin.socket.yinfei.handler.AbstractMessageHandler;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.Session;

/**
 * @author Tang
 * @classname AbstractParameterDataConnection
 * @description [  ]
 * @date 2021/8/17 23:15
 */
@Slf4j
public abstract class AbstractParameterDataConnection extends AbstractWebSocketConnection {

    @Getter
    AbstractMessageHandler abstractMessageHandler;

    @Override
    public void onMessage(String message, Session session) {
        super.onMessage(message, session);
        if (session.isOpen()) {
            Object result = null;
            try {
                result = abstractMessageHandler.handler(message);
                session.getBasicRemote().sendObject(result);
            } catch (Exception e) {
                log.info("数据发送异常:{}", result);
            }
        }
    }
}